from PyQt4.Qt import *
from PyQt4 import QtGui
from PyQt4.QtGui import QWidget, QPushButton, QMainWindow
from PyQt4 import QtCore
from PyQt4.Qwt5 import *
from PyQt4.Qwt5.qplt import QwtPlot

from math import trunc as t
from random import random as r
import sys

class Visualizer(QwtPlot):
	"""QwtPlot extansion that automatically visualize data (in red), average of data (in blue) and standard deviation (in black).
	"""
	def __init__(self, *args):
		QwtPlot.__init__(self, *args)
	
	def visualize(self, listwrap):
		"""Function that set up the plot. 
		listwrap must be a ListWrapper class or implements toarray(), average() and deviation()
		"""
		self.clear()

		# init data
		x = range(len(listwrap))

		# create curve
		curve = QwtPlotCurve("data")
		curve.setData(x, [i for i in listwrap])
		curve.attach(self)
		curve.setPen(QPen(Qt.red))

		# create average
		a = QwtPlotCurve("average")
		a.setData(x, [listwrap.average for i in x])
		a.attach(self)
		a.setPen(QPen(Qt.blue))
		
		# create deviation
 		d = QwtPlotCurve("standard deviation")
 		d.setData(x, [listwrap.deviation for i in x])
 		d.attach(self)
 		d.setPen(QPen(Qt.black))

		# draw
		self.replot()
	
